import re
import requests
from bs4 import BeautifulSoup
import time

url = 'https://movie.douban.com/top250'
r = requests.get(url, headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'})
soup = BeautifulSoup(r.text, 'lxml')
rank = soup.select('ol em')     #获取排名
for rank in rank:
    print(rank.text,end='')

Movie_Url = soup.select('ol .info .hd')   #获取电影url
for movie_url in Movie_Url:
    print(movie_url.a.attrs['href'])

Movie_Name = soup.select('ol .info .hd a .title')   #获取电影名
for movie_name in Movie_Name:
    print(movie_name.string.replace('\xa0',''),end='')

DirecAndActor = soup.select('ol .info .bd p',class_=None)    #获取导演演员
for direcandactor in DirecAndActor:
    print(direcandactor.text.replace('\xa0','').strip())

People = soup.select('ol .info .bd .star span')   #获取评价人数 评分
for people in People:
    print(people.string)
